package org.huhu.mercury.fabric.test;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import org.yaml.snakeyaml.Yaml;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by yfx on 2017/7/15.
 */
@RunWith(SpringJUnit4ClassRunner.class)  //使用junit4进行测试
@ContextConfiguration({"classpath:META-INF/spring/mercury-web-integration.xml"}) //加载配置文件
@Transactional
@ActiveProfiles("dev")
public class InitData {

    String cryptoConfigPath="/channel/crypto-config.yaml";

    @Test
    public void initBcOrg() throws IOException {
        String cryptoConfig= IOUtils.toString( InitData.class.getClassLoader().getResourceAsStream("/channel/configtx.yaml"),"UTF-8");
        System.out.println(cryptoConfig);
    }

    public static void main(String[] args) throws IOException {
        String cryptoConfig= IOUtils.toString( InitData.class.getClassLoader().getResourceAsStream("channel/crypto-config.yaml"),"UTF-8");
        System.out.println(cryptoConfig);
        Yaml yaml = new Yaml();
        Map<String,Object> result= (Map<String,Object>)yaml.load(cryptoConfig);
        List<Map<String,Object>> ordererOrgs=(List<Map<String,Object>>)result.get("OrdererOrgs");
        for(Map<String,Object>  ordererOrg:ordererOrgs){
            System.out.println(ordererOrgs);
        }
        List<Map<String,Object>> peerOrgs=(List<Map<String,Object>>)result.get("PeerOrgs");
    }
}
